package org.micode.demo.db.domain.entity;

import com.fasterxml.jackson.annotation.JsonIgnore;
import org.micode.common.validater.InsertGroup;
import org.micode.common.validater.UpdateGroup;
import org.micode.common.validater.EnumValidation;
import org.micode.common.exception.VerifyFailException;
import org.micode.common.utils.StringExtUtils;
import org.micode.common.domain.base.entity.BaseUpdEntity;

import lombok.Data;
import lombok.EqualsAndHashCode;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.PositiveOrZero;
import javax.validation.constraints.Size;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;

/**
 * 客户端应用实体类
 *
 * @author: wutianbin
 * @version: v1.0.27
 * @CreateDate: 2021-11-10
 */
@EqualsAndHashCode(callSuper = true)
@Data
public class SysClientDO extends BaseUpdEntity<Long> {

    /** 客户端ID，Long */
    @NotNull(message = "客户端ID,不能为空", groups = UpdateGroup.class)
    @PositiveOrZero(message = "客户端ID,不能为负数", groups = {InsertGroup.class, UpdateGroup.class})
    private Long clientId;

    /** 应用代码，代码中不能包含|，String */
    @NotNull(message = "应用代码，代码中不能包含|,不能为空", groups = InsertGroup.class)
    @Size(max = 32,message = "应用代码，代码中不能包含|,最大长度32个字", groups = {InsertGroup.class, UpdateGroup.class})
    private String clientCode;

    /** 应用名称，String */
    @NotNull(message = "应用名称,不能为空", groups = InsertGroup.class)
    @Size(max = 64,message = "应用名称,最大长度64个字", groups = {InsertGroup.class, UpdateGroup.class})
    private String clientName;

    /** 应用类型, 枚举类型: ClientTypeEnum，Integer */
    private Integer clientType;

    /** 排序编码，Integer */
    private Integer sortNo;

    /** 禁用标识, 枚举类型: DisableFlagEnum，Integer */
    private Integer disableFlag;

    /** 备注说明，String */
    @Size(max = 512,message = "备注说明,最大长度512个字", groups = {InsertGroup.class, UpdateGroup.class})
    private String description;

    @JsonIgnore
    @Override
    public Long getKeyValue() {
        return clientId;
    }

    @Override
    public void checkBeforeInsert() {
        if (StringExtUtils.isAnyEmpty(clientCode)) {
            throw new VerifyFailException("SysClientDO.clientCode 必须非空");
        }
        if (StringExtUtils.isAnyEmpty(clientName)) {
            throw new VerifyFailException("SysClientDO.clientName 必须非空");
        }
    }

    @Override
    public String toString() {
        return "clientId=" + clientId +
                ", clientCode='" + clientCode + "'" +
                ", clientName='" + clientName + "'" +
                ", clientType=" + clientType +
                ", sortNo=" + sortNo +
                ", disableFlag=" + disableFlag +
                ", description='" + description + "'" +
                ", " + super.toString();
    }

}
